#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main()
{
    pid_t id=fork();
    if(id==0)
    {
        int cnt=5;
        while(cnt--)
        {
            printf("我是子进程,pid:%d,ppid:%d,cnt:%d\n",getpid(),getppid(),cnt);
            sleep(1);
        }
        exit(4);
    }
    int status=0;
    pid_t ret_id=0;
    do
    {
     // 父进程执行内容 循环等待
       ret_id = waitpid(-1,&status,WNOHANG);
       if(ret_id==0)
       {
          printf("child is running\n");
       }
       sleep(1);
    }while(ret_id == 0);
    if(ret_id>0)
    {
     printf("father wait:%d sucess,status wait code:%d,status exit  signal:%d\n",ret_id,WEXITSTATUS(status),WIFEXITED(status));
   }
   else
   {
     printf("father wait failed!\n");
   } 
    return 0;
}